package com.skydonkey.controller;


import com.github.pagehelper.Page;
import com.skydonkey.config.RabbitConfig;
import com.skydonkey.pojo.dto.VideoConversionDto;
import com.skydonkey.pojo.po.VideoInfo;
import com.skydonkey.service.VideoService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    VideoService videoService;

    @RequestMapping(value = "/mq/{message}", method = RequestMethod.GET)
    public String mp4toFlvMqMsgTest(@PathVariable("message") String message) {
        VideoConversionDto videoConversionDto = new VideoConversionDto().setVideoId(1L)
                .setVideoKey("keykeykey")
                .setPersistId("aaaaa")
                .setVideoOriginalFormat("mp4")
                .setVideoTargetFormat("flv")
                .setStatusCode(-1);

        rabbitTemplate.convertAndSend(
                RabbitConfig.CONVERSION_EXCHANGE_NAME,
                RabbitConfig.CONVERSION_MP4_TO_FLV_ROUTING_KEY,
                videoConversionDto);
        return videoConversionDto.toString();
    }

    @RequestMapping(value = "/video/{pageNum}/{count}", method = RequestMethod.GET)
    public String getVideoByPage(@PathVariable("pageNum") Integer pageNum,
                                 @PathVariable("count") Integer pageCount) {
        Page<VideoInfo> all = videoService.findAll(pageNum, pageCount);
        List<VideoInfo> result = all.getResult();
        return result.toString();
    }
}
